package com.rchat.pocmini.activity.searchgroup;

import com.airtalkee.sdk.AirtalkeeAccount;
import com.aso.common.http.bean.BaseBean;
import com.aso.common.http.delegate.HttpCallbackImpl;
import com.rchat.pocmini.R;
import com.rchat.pocmini.bean.SearchGroupBean;
import com.rchat.pocmini.global.HttpCodeGlobal;
import com.rchat.pocmini.global.UrlsGlobal;
import com.rchat.pocmini.util.HttpUtil;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Created by ljd on 2017/7/31.
 */

public class SearchGroupPresenterImpl extends SearchGroupContract.Presenter {

    private boolean isSearching = false;

    @Override
    void searchGroup(String groupName) {
        if (isSearching) {
            mView.showShortToast(R.string.is_searching);
            return;
        }
        if (groupName == null || groupName.equals("")) {
            mView.showShortToast(R.string.group_name_null_error);
            return;
        }

        isSearching = true;

        mModel.searchGroup(groupName, new HttpCallbackImpl<SearchGroupBean>() {
            @Override
            public void onStart() {

            }

            @Override
            public void onSuccess(SearchGroupBean searchGroupBean) {
                if (mView == null) {
                    return;
                }
                isSearching = false;
                mView.notifyDataChanged(searchGroupBean);
            }

            @Override
            public void onFailureResult(BaseBean bean) {
                if (mView == null) {
                    return;
                }
                isSearching = false;
                switch (bean.getCode()) {
                    case HttpCodeGlobal.RES_CODE_408 + "":
//                        searchResult.clear();
//                        adapter.notifyDataSetChanged();
                        mView.showShortToast(R.string.group_not_exit);
                        break;
                    default:
                        mView.showNetError(bean.getCode(), bean.getDesc());
                        break;
                }
            }

            @Override
            public void onFinish() {

            }
        });
    }
}
